/**
 * 动态设置-table列表个性设置
 */
export default {
    data() {
        return {
            
        }
    },
    methods: {
        /**
         * 拖动表头宽度
         * @param {*} newWidth
         * @param {*} oldWidth
         * @param {*} column 列数据之中有className，需要自行设置
         * @param {*} event
         */
        dragHeader(newWidth, oldWidth, column, event) {
            const that = this;

            // console.log('拖动列新宽度', newWidth);

            if(that[column.className]){
                // 重新深拷贝一个数据
                let cols = that.U.scopy(that[column.className].columns);
                cols.forEach(it => {
                    if (it.field == column.property) it.width = newWidth;
                });
                // 最后重新赋值，监听器会执行改变
                that[column.className].columns = cols;

                that.$refs[that[column.className].tbName].doLayout();
            }
        },
        // 保存表格个性设置
        saveTbSet(e) {
            const that = this;
            
            that[e.dgName].columns = that.U.scopy(e.cols);

            // console.log('当前列表显示列', that[e.dgName].columns);

            that.$nextTick(() => {
                that.$refs[that[e.dgName].tbName].doLayout();
            });
        },
        /**
         * 获取-表格设置
         * @param {*} dgName 表格数据对象名称
         */
        initTbSetData(dgName) {
            const that = this;

            // 准备初始数据
            let tbSet = sessionStorage.getItem(that[dgName].tbName);
            if(tbSet){
                let cols = JSON.parse(tbSet);

                let list = cols.filter(it => {return it.show;});
                that[dgName].columns = list;
            }else{
                that[dgName].srcCols.forEach(it => { it.show = true; });
                that[dgName].columns = that.U.scopy(that[dgName].srcCols);

                // console.log('第一次：传入的拖动列', that[dgName].srcCols);
                // console.log('第一次：传入的表格列', that[dgName].columns);
            }
        },
        

    },
}
